<?php
require '../header.php';
if(isPosts()){
    $username = trim($_POST['username']);
    $password = trim($_POST['password']);
    if(empty($username)){
        retJson(-1,'请输入用户名');
    }
    if(strlen($password) < 6){
        retJson(-1,'密码不能小于六位');
    }
    $data = [
        'username' => $username,
        'password' => $password,
        'create_time' => time()
    ];
    $res = $db->table('lh_user')->insert($data);
    $insert_id = $db->get_insert_id();
    $find = $db->table('lh_user')->where("id={$insert_id}")->field('*')->find();
    $find['status_name'] = $find['status'] == 1 ? '正常' : '暂停';
    $find['create_time_show'] = date('Y-m-d',$find['create_time']);
    if($res){
        retJson(1,'添加成功',$find);
    }else{
        retJson(-1,'添加失败');
    }
}else{
    retJson(-1,'非法操作');
}
